﻿using System;
using nRoute.Components.Composition;
using nRoute.Internal;

namespace nRoute.ViewServices
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly,
        AllowMultiple = true, Inherited = false)]
    public class DefineViewServiceAttribute
		 : MapViewServiceAttribute
    {
        private readonly Type _implementationType;

        public DefineViewServiceAttribute(Type viewServiceType, Type implementationType)
		 : this(viewServiceType, implementationType, null) { }

        public DefineViewServiceAttribute(Type viewServiceType, Type implementationType, string name, 
            params Type[] dependencies)
		 : base(viewServiceType, name)
        {
            Guard.ArgumentNotNull(implementationType, "implementationType");
            EnsureIsViewServiceType(implementationType, viewServiceType);

            // and we save the reference
            _implementationType = implementationType;
        }

#region Overrides

        protected internal override IResourceLocator GetResourceLocator(Type targetType)
        {
            // we overide the target type
            return base.GetResourceLocator(_implementationType);
        }

#endregion

    }
}
